package com.asset.modules.system.service.impl;


import com.asset.modules.system.mapper.CompanyMapper;
import com.asset.modules.system.model.Company;
import com.asset.modules.system.service.CompanyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author asset
 * @since 2020-08-13
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {

    private static final Logger logger = LoggerFactory.getLogger(CompanyServiceImpl.class);



    @Transactional(rollbackFor = Exception.class)
    public List<Company> getAll(){
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNotNull("company_code");
        return list(queryWrapper);
    }

    @Override
    public List<String> removeByIdsWithChecking(List<? extends Collection> ids) {
        return null;
    }


    /**
     * 根据code获取公司信息
     * @param code
     * @return
     */
    @Override
    public Company getCompanyByCode(String code){
        QueryWrapper<Company> qw = new QueryWrapper<>();
        qw.eq("company_code", code);
        return getOne(qw);
    }

    @Override
    public boolean isExist(String column, String name) {
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(column, name);
        List result = list(queryWrapper);
        if(result.size()>0){
            return true;
        }
        return false;
    }

    @Override
    public Company getCompanyByName(String name) {
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_name", name);
        return getOne(queryWrapper);
    }
}
